<template>
  <vxe-modal
    v-model="showModal"
    show-footer
    show-zoom
    :show-maximize="false"
    :mask="maskLock"
    :lock-view="maskLock"
    class-name="au-modal"
    v-bind="$attrs"
    @zoom="zoom"
    @close="closePopup"
  >
    <template #title="{ minimized }">
      <div v-if="minimized">标题</div>
      <div v-else>
        <slot v-if="$slots.title" name="title" />
        <span v-else>{{ $attrs.title }}</span>
      </div>
    </template>
    <template #footer>
      <div class="flex items-center h-full">
        <slot name="footer_left" />
        <div class="ml-auto h-full">
          <el-button v-if="showCancel" @click="closePopup"
            >{{ $t("buttons.pureCancel") }}
          </el-button>
          <el-button v-if="showConfirm" type="primary" @click="handleConfirm"
            >{{ confirmTitle || $t("buttons.pureConfirm") }}
          </el-button>
        </div>
      </div>
    </template>
    <slot />
  </vxe-modal>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  },
  showConfirm: {
    type: Boolean,
    default: true
  },
  showCancel: {
    type: Boolean,
    default: true
  },
  confirmTitle: {
    type: String,
    default: ""
  }
});
const maskLock = ref(true);

const emit = defineEmits(["update:modelValue", "close", "handleConfirm"]);

const showModal = computed({
  get: () => props.modelValue,
  set: val => {
    emit("update:modelValue", val);
  }
});

// const hasTitleSlot = computed(() => !!slots.title);

const handleConfirm = () => {
  emit("handleConfirm");
};

const closePopup = () => {
  showModal.value = false;
  emit("close");
};

const zoom = ({ type, $event }) => {
  maskLock.value = type !== "minimize";
};
</script>

<style lang="scss">
.au-modal {
  .vxe-modal--header-title {
    padding: 14px 20px;
    font-size: 14px;
    color: var(--autata-font-color);
  }

  .vxe-modal--header-right {
    .vxe-modal--close-btn,
    .vxe-modal--zoom-btn {
      color: var(--autata-font-gray-color);
    }
  }
}
</style>
